package com.example.viewex;

import android.os.Bundle;
import android.app.Activity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;

public class WebViewActivity extends Activity {

	WebView wv;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.webview);
		
		wv = (WebView)findViewById(R.id.webView1);
		wv.setWebViewClient(new WebViewClient());
		
		wv.getSettings().setJavaScriptEnabled(true);	// 자바 스크립트 기능 활성화
		wv.getSettings().setUseWideViewPort(true);		// 좌우 스크롤 활성화
		wv.getSettings().setSupportZoom(true);			// zoom 기능 활성화
		wv.getSettings().setBuiltInZoomControls(true);	// 멀티 터치
	}
	
	public void onClick(View v) {
		
		EditText et = (EditText)findViewById(R.id.editText1);
		
		String url = "http://" + et.getText().toString();
		wv.loadUrl(url);
	}
	
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode == KeyEvent.KEYCODE_BACK && wv.canGoBack()) {
			wv.goBack();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

		new OptionMenu(this, item);
		
		return super.onOptionsItemSelected(item);
	}
}
